package com.example.tellwin.mine.presenter;

import android.text.TextUtils;

import com.apkfuns.logutils.LogUtils;
import com.example.tellwin.MainApplication;
import com.example.tellwin.api.TwjfApi;
import com.example.tellwin.base.RxPresenter;
import com.example.tellwin.base.SimpleCallback;
import com.example.tellwin.home.bean.ContentBean;
import com.example.tellwin.mine.contract.BindContract;
import com.example.tellwin.mine.contract.MineDetailContract;
import com.example.tellwin.utils.HttpUtils;
import com.example.tellwin.utils.ToastUtil;
import com.google.gson.JsonObject;

import java.io.File;

import javax.inject.Inject;

import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;

/**
 * @author : LinZePeng
 * @date : 2020/12/1
 * @Describe ：
 **/
public class BindPresenter extends RxPresenter<BindContract.View> implements BindContract.Presenter<BindContract.View> {

    private TwjfApi mApi;

    @Inject
    public BindPresenter(TwjfApi mApi) {
        this.mApi = mApi;
    }


    @Override
    public void updateUserInfo(JsonObject jsonObject) {
        LogUtils.e(jsonObject.toString());
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), jsonObject.toString());
        mApi.updateUserInfo(requestBody, new SimpleCallback<Object>(mView) {
            @Override
            public void onSuccess(Object o) {
                mView.updateUserInfoResult();
            }

            @Override
            public void onFail(String msg) {

            }
        });
    }

    @Override
    public void getAliAuthToken() {

        mApi.getAliAuthToken(new SimpleCallback<ContentBean>(mView) {
            @Override
            public void onSuccess(ContentBean contentBean) {
                if (TextUtils.isEmpty(contentBean.getApiname())) {
                    ToastUtil.show(MainApplication.getContext(), "获取支付宝参数失败！");
                    return;
                }
                mView.aliAuthToken(contentBean.getApiname());
            }

            @Override
            public void onFail(String msg) {

            }
        });
    }

    @Override
    public void uploadAliToken(String aliToken) {
        RequestBody requestBody = HttpUtils.getRequestBody("zfbUserId", aliToken);
        mApi.uploadAliToken(requestBody, new SimpleCallback<ContentBean>(mView) {
            @Override
            public void onSuccess(ContentBean contentBean) {
                mView.uploadAliTokenSuccess();
            }

            @Override
            public void onFail(String msg) {

            }
        });
    }

}
